class goods {
    constructor() {
        // 执行幻灯片功能
        this.slide();
        // 执行点击图显示详情
        this.details();
        // 计数器
        this.num = 0;
    }
    details() {
        // 点击元素 显示商品详情
        $(".content_r_goods_list").delegate("a","click",function() {
            $(".shop_n").css("display","block");
            $(".content_con_r_con").css("display","none");
            let goods = [
                {
                    goodsId:"300001",
                    goodsImg:[
                        "http://21206385.s21i.faiusr.com/2/ABUIABACGAAgztSQ8AUoxP-unQIwoAY4oAY.jpg"
                    ],
                    goods_details:[
                        "http://21206385.s21i.faiusr.com/2/ABUIABACGAAg_6WR8AUotYfOggMwnAY4zgQ.jpg"
                    ],
                    goodsList:[]
                },
                {
                    goodsId:"300002",
                    goodsImg:[
                        "http://21206385.s21i.faiusr.com/2/ABUIABACGAAgvdSQ8AUo-sykuAMw6AI46AI.jpg",
                        "http://21206385.s21i.faiusr.com/2/ABUIABACGAAgztSQ8AUo5OuIygIwoAY4oAY.jpg",
                        "http://21206385.s21i.faiusr.com/2/ABUIABACGAAgztSQ8AUoi-LDXTCgBjigBg.jpg",
                        "http://21206385.s21i.faiusr.com/2/ABUIABACGAAgztSQ8AUogMP_nQcwoAY4oAY.jpg",
                        "http://21206385.s21i.faiusr.com/2/ABUIABACGAAgztSQ8AUoxP-unQIwoAY4oAY!60x60.jpg"
                    ],
                    goods_details:[
                        "http://21206385.s21i.faiusr.com/2/ABUIABACGAAgztSQ8AUo5OuIygIwoAY4oAY.jpg"
                    ],
                    goodsList:[
                        "http://21206385.s21i.faiusr.com/2/ABUIABACGAAgvdSQ8AUo-sykuAMw6AI46AI!60x60.jpg",
                        "http://21206385.s21i.faiusr.com/2/ABUIABACGAAgztSQ8AUo5OuIygIwoAY4oAY!60x60.jpg",
                        "http://21206385.s21i.faiusr.com/2/ABUIABACGAAgztSQ8AUoi-LDXTCgBjigBg!60x60.jpg",
                        "http://21206385.s21i.faiusr.com/2/ABUIABACGAAgztSQ8AUogMP_nQcwoAY4oAY!60x60.jpg",
                        "http://21206385.s21i.faiusr.com/2/ABUIABACGAAgztSQ8AUoxP-unQIwoAY4oAY!60x60.jpg"
                    ]
                }
            ];
            console.log($(this).attr("data-goodsId"));
            let str = "";
            for (let i=0; i<goods.length; i++) {
                if ($(this).attr("data-goodsId") === goods[i].goodsId) {
                    goods[i].goodsList.forEach(item => {
                        str += `
                        <li class="xun_li">
                            <img src="${item}" alt="">
                        </li>`;
                    });
                    $(".xun_list").html(str);
                    str = "";
                    goods[i].goodsImg.forEach(item => {
                        str += `
                        <li class="img_li">
                            <img src="${item}" alt="">
                        </li>`;
                    });
                    $(".img_list").html(str);
                    str = "";
                    goods[i].goods_details.forEach(item => {
                        str += `
                        <img src="${item}" alt="">`;
                    });
                    $(".shop_right_bottom_img").html(str);
                }
            }
        })
    }
    slide() {
        let _this = this;
        $(".slide-con").delegate("a", "click", function () {
            // 点击弹出
            $(".modalBox").css("display","block");
            
            // 根据点击索引渲染页面
            window.index("getData",window.i);
            setTimeout(() => {
                // 设置默认样式
                $(".modalBox_main_left > img").attr("src",window.goodsListRes[0].goodsImg);
                $(".modalBox_main_right > h3").html(window.goodsListRes[0].goodsTit);
            }, 300);
        });
        $(".modalBox_con_close").click(function() {
            // 点击隐藏
            $(".modalBox").hide("normal");
        });
        // 点击按钮切换图片与标题
        $(".nextBtn").click(function() {
            _this.replace(1);
        });
        $(".prevBtn").click(function() {
            _this.replace(-1);
        });
    }
    replace(i) {
        if ( i === 1 ) {
            if (this.num > window.goodsListRes.length-2) this.num = 0;
            else this.num++;
        } else {
            if (this.num < 1) this.num = window.goodsListRes.length-1;
            else this.num--;
        }
        $(".modalBox_main_left > img").attr("src",window.goodsListRes[this.num].goodsImg);
        $(".modalBox_main_right > h3").html(window.goodsListRes[this.num].goodsTit);
    }
}
new goods;


